@extends('admin.layouts.head')
@section('content')
    <body>
    <div id="app">
        <div class="wrapper -header-fixed">

        @include('admin.layouts.navbar')
        @include('admin.layouts.sidebar')

        <!-- 内容页开始-->
            <div class="content-container">
                <div class="container-fluid">
                    <div class="page-content">

                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">仪表盘</a></li>
                                <li class="breadcrumb-item"><a href="{{ route('admin.users.index') }}">用户列表</a></li>
                                <li class="breadcrumb-item active" aria-current="page">修改@if ($_GET['type']==='mobile') 手机 @else 余额 @endif</li>
                            </ol>
                        </nav>

                        <div class="card">
                            <div class="card-body">

                                <div class="row">
                                    <div class="col-lg-5">
                                        @if ($_GET['type']==='ly')
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>乐游币：</label>
                                                <input type="text" class="form-control" id="balance-val"
                                                       value="{{ $userDataInfo->ly_balance }}" >
                                            </div>
                                        </div>
                                       @elseif ($_GET['type']==='red')
                                            <div class="col-lg-12">
                                                <div class="form-group">
                                                    <label>红包币：</label>
                                                    <input type="text" class="form-control" id="balance-val"
                                                           value="{{ $userDataInfo->red_packet_coin }}" >
                                                </div>
                                            </div>
                                        @elseif ($_GET['type']==='wf')
                                            <div class="col-lg-12">
                                                <div class="form-group">
                                                    <label>玩服积分：</label>
                                                    <input type="text" class="form-control" id="balance-val"
                                                           value="{{ $userDataInfo->wf_integral }}" >
                                                </div>
                                            </div>
                                        @elseif ($_GET['type']==='total')
                                            <div class="col-lg-12">
                                                <div class="form-group">
                                                    <label>累计积分：</label>
                                                    <input type="text" class="form-control" id="balance-val"
                                                           value="{{ $userDataInfo->cumulative_points }}" >
                                                </div>
                                            </div>
                                        @elseif ($_GET['type']==='mobile')
                                            <div class="col-lg-12">
                                                <div class="form-group">
                                                    <label>手机：</label>
                                                    <input type="text" class="form-control" id="balance-val"
                                                           value="{{ $userDataInfo->mobile }}" >
                                                </div>
                                            </div>

                                        @elseif ($_GET['type']==='birthday')
                                            <div class="col-lg-12">
                                                <div class="form-group">
                                                    <label>生日：[例: 2001-01-02]</label>
                                                    <input type="text" class="form-control" id="balance-val"
                                                           value="{{ $userDataInfo->birthday }}" >
                                                </div>
                                            </div>
                                        @elseif ($_GET['type']==='newRedPacketCoin')
                                            <div class="col-lg-12">
                                                <div class="form-group">
                                                    <label>新红包币</label>
                                                    <input type="text" class="form-control" id="balance-val"
                                                           value="{{ $userDataInfo->new_red_packet_coin }}" >
                                                </div>
                                            </div>
                                        @elseif ($_GET['type']==='relatedInfo')
                                            <div class="col-lg-12">
                                                <div class="form-group">
                                                    <label>微信名称</label>
                                                    <input type="text" class="form-control" id="balance-username-val"
                                                           value="{{ $userDataInfo->username }}" >
                                                </div>
                                                <div class="form-group">
                                                    <label>微信账号</label>
                                                    <input type="text" class="form-control" id="balance-wx-account-val"
                                                           value="{{ $userDataInfo->wx_account }}" >
                                                </div>
                                                <div class="form-group">
                                                    <label>QQ号</label>
                                                    <input type="text" class="form-control" id="balance-qq-val"
                                                           value="{{ $userDataInfo->qq }}" >
                                                </div>
                                                <div class="form-group">
                                                    <label>真实姓名</label>
                                                    <input type="text" class="form-control" id="balance-name-val"
                                                           value="{{ $userDataInfo->name }}" >
                                                </div>
                                            </div>
                                        @else
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>商城积分：</label>
                                                <input type="text" class="form-control" id="balance-val"
                                                       value="{{ $userDataInfo->integral }}" >
                                            </div>
                                        </div>
                                        @endif
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <button class="btn btn-primary" onclick="operation_tip2({{ $userDataInfo->id }})">提交</button>
                                            </div>
                                        </div>
                                    </div>

                                </div> <!-- .row -->
                            </div> <!-- .card-body -->
                        </div> <!-- .card -->

                    </div> <!-- .page-content -->
                </div> <!-- .container-fluid -->
            </div> <!-- .content-container -->
        </div> <!-- .wrapper -->
    </div> <!-- #app -->

    <script src="{{ mix('js/app.js') }}"></script>
    <script src="{{ asset('/js/main.js') }}"></script>
    <script>

        function getUrlParam(name) {
            let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            let r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURI(r[2]);
            return '';
        }

        let isLoading = false;

        //提交
        function submit(id) {

            if ( ! $('#balance-val').val() &&  getUrlParam('type') != 'relatedInfo' ) {
                toast('金额 不能为空。');
                return false
            }



            if (isLoading === false) {
                isLoading = true;

                axios.post('{{ route('admin.users.setBalance')}}', {
                    id: id,
                    tp: getUrlParam('type'),
                    balance: $('#balance-val').val() || "",
                    // username: $('#balance-username-val').val() || "",
                    // wxAccount: $('#balance-wx-account-val').val() || "",
                    // qq: $('#balance-qq-val').val() || "",
                    // name: $('#balance-name-val').val() || "",

                })
                    .then(function (response) {
                        isLoading = false;
                        toast(response.data.message);
                        setTimeout(function () {
                            location.href = '/admin/users'
                        }, 2000)
                    })
                    .catch(function (error) {
                        isLoading = false;
                        $.each(error.response.data.errors, function (index, object) {
                            toast(object[0]);
                            return false;
                        });
                    })
            }
        }
    </script>

    </body>

@endsection
